package com.ruitu.health_2.ui.mall;

import android.os.Bundle;

import com.ruitu.health_2.mvp.model.ProductModel;
import com.ruitu.health_2.mvp.presenter.ProductPresenter;
import com.ruitu.health_2.ui.common.ProductListActivity;
import com.ruitu.router_module.bean.PageModel2;
import com.ruitu.router_module.bean.product.ProHome;

import java.util.List;

// 根据商城栏目columnId查询该栏目下的商品
public class ProductListByColumnActivity extends ProductListActivity<ProductPresenter.ProGridP, ProductModel.ProGridM> {

    private String columnId;// 传过来的栏目id
    private String columnName = "商品列表";// 传过来的栏目名称

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Bundle bundle = getIntent().getExtras();
        if (null != bundle) {
            columnId = getIntent().getStringExtra("columnId");
            columnName = getIntent().getStringExtra("columnName");
        }
        super.onCreate(savedInstanceState);

        setHeadTitle(columnName);
    }

    @Override
    protected void reqDataList() {
        p.reqProListByColumn(20, currPage, columnId);
    }

    @Override
    public void onReqComplete(int code, boolean isOk, Object data) {
        if (code == 11) {
            if (currPage == 1) {
                proList.clear();
            }
            PageModel2<ProHome> proPage = (PageModel2<ProHome>) data;
            totalPage = proPage.getTotalPage();
            List<ProHome> newData = proPage.getList();
            proList.addAll(newData);
            proAdapter.setDataList(proList);

            showOrHideEmptyView();
        }
    }
}
